package com.zxh.listdemo.adapter.list;

import android.support.annotation.Nullable;
import android.util.SparseIntArray;

import com.zxh.listdemo.R;
import com.zxh.listdemo.adapter.list.common.BaseMultiListAdapter;
import com.zxh.listdemo.adapter.list.common.BaseMultiModel;
import com.zxh.listdemo.adapter.list.common.BaseViewHolder;
import com.zxh.listdemo.model.MultiModel;
import com.zxh.listdemo.model.OneModel;
import com.zxh.listdemo.model.TwoModel;

import java.util.List;

import static com.zxh.listdemo.Config.ITEM_IMG;
import static com.zxh.listdemo.Config.ITEM_TEXT;

/**
 * Created by zhangxuehui on 2018/3/5.
 */
public class MultiBaseAdapter extends BaseMultiListAdapter<BaseMultiModel> {


    public MultiBaseAdapter(@Nullable List<BaseMultiModel> multiModels) {
        super(multiModels);
    }

    @Override
    protected void addLayoutIds() {
        addLayoutId(ITEM_TEXT, R.layout.item_two);
        addLayoutId(ITEM_IMG, R.layout.item_one);
    }

    @Override
    public void convert(BaseViewHolder holder, int position) {
        int itemType = getItemViewType(position);
        BaseMultiModel model = getItem(position);
        if (itemType == ITEM_TEXT) {
            if (checkTypeForModel(position, TwoModel.class)) {
                holder.setText(R.id.tv_desc, ((TwoModel) model).getContent());
            }
        } else if (itemType == ITEM_IMG) {
            if (checkTypeForModel(position, OneModel.class)) {
                holder.setText(R.id.tv_title, ((OneModel) model).getTitle())
                        .setText(R.id.tv_desc, ((OneModel) model).getDesc())
                        .setImageUrl(R.id.iv_icon, ((OneModel) model).getLink());
            }
        }
    }
}